<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\model\OrderTemporary;
use app\common\model\ProductCart;
use app\common\tool\Result;
use think\facade\View;
use think\Response;

class Cart extends Base
{
    public function index(): string
    {
        $map = ['uid' => $this->user->id];
        $list = ProductCart::getList($map, false, 'update_time', ['product']);
        View::assign('list', $list);

        return View::fetch();
    }

    public function add(): Response
    {
        $param = $this->request->post();

        return Result::fastReturn(ProductCart::add($param, $this->user));
    }

    public function edit(): Response
    {
        $param = $this->request->post();

        return Result::fastReturn(ProductCart::edit($param, $this->user));
    }

    public function submit(): Response
    {
        $param = $this->request->post();
        $param['type'] = 2;

        return Result::fastReturn(OrderTemporary::setTemporary($param, $this->user));
    }
}